package com.yjy.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;

import com.system.comm.util.SpringContextUtil;
import com.system.common.mapper.BisShopPostMapper;
import com.system.common.mapper.BisShopUserMapper;
import com.system.common.pojo.BisShopPost;
import com.system.common.pojo.BisShopUser;

public class PostCodeTag extends BodyTagSupport{
	
	private static final long serialVersionUID = 1L;
	private String postCode;
	
	public String getPostCode() {
		return postCode;
	}

	public void setPostCode(String postCode) {
		this.postCode = postCode;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	
	@Override
	public int doStartTag() throws JspException { // 在标签开始处出发该方法
		JspWriter writer = this.pageContext.getOut();
		BisShopUserMapper bisShopUserMapper=(BisShopUserMapper)SpringContextUtil.getBean("bisShopUserMapper");
		BisShopPostMapper bisShopPostMapper=(BisShopPostMapper)SpringContextUtil.getBean("bisShopPostMapper");
		try {
			BisShopUser user=bisShopUserMapper.selectByPrimaryKey(postCode);
			BisShopPost post=bisShopPostMapper.queryBypostcode(user.getPostCode());
			if(post!=null){
				writer.write(post.getPostName());
			}else{
				writer.write("");
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return BodyTagSupport.SKIP_BODY;
	}

	@Override
	public int doEndTag() throws JspException {
		return BodyTagSupport.EVAL_BODY_INCLUDE;
	}
	
}
